8615. Outside the interval

 

Determine whether the number x is outside the interval [ab]. The number x is outside the interval [ab] if either x < a or x > b.

 

Input. Three integers xab, each not exceeding 109 in absolute value.

 

Output. Print “OUT” if the number x does not belong to the interval [a; b]. Otherwise, print “IN”.

 

Sample input 1

Sample output 1

7 2 7

IN

 

 

Sample input 2

Sample output 2

-5 1 1

OUT

 

 

SOLUTION

conditional statement

 

Algorithm analysis

Lets combine the conditions x < a and x > b using the or (||) operator.

 

Algorithm implementation

Read the input data.

 

scanf("%d %d %d", &x, &a, &b);

 

Print the answer depending on whether the number x is outside or inside the interval [ab].

 

if (x < a || x > b)

  printf("OUT\n");

else

  printf("IN\n");

 

Java implementation

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int x = con.nextInt();

    int a = con.nextInt();

    int b = con.nextInt();

    if (x < a || x > b)

      System.out.println("OUT");

    else

      System.out.println("IN");

    con.close();

  }

}

 

Python implementation

Read the input data.

 

x, a, b = map(int,input().split())

 

Print the answer depending on whether the number x is outside or inside the interval [ab].

 

if x < a or x > b:

  print("OUT")

else:

  print("IN")